import axios from 'axios';

// 获取商品列表
function getGoods(classify) {
  return new Promise((resolve, reject) => {
    axios
      .get(`/getGoods`, {
        params: { classify: classify },
      })
      .then((result) => {
        if (result.data.ok == 1) resolve(result.data.result);
        else reject();
      });
  });
}

// 搜索商品
function searchGoods(page, keyword) {
  return new Promise((resolve, reject) => {
    axios
      .get(`/searchGoods`, {
        params: { page, keyword },
      })
      .then((result) => {
        if (result.data.ok == 1) resolve(result.data);
        else reject();
      });
  });
}

// 获取商品详情
function getGoodDetail(gid) {
  return new Promise((resolve, reject) => {
    axios.get(`/getGood/${gid}`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

// 获取商品详情图
function getDatileImg(gid) {
  return new Promise((resolve, reject) => {
    axios.get(`/getDatileImg/${gid}`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

export { getGoods, searchGoods, getGoodDetail, getDatileImg };
